package com.haiwen.com;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
* 这个类是HttpServletRequest的方法演示*/
@WebServlet("/request")
public class HttpServleRequest extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        //1.获取完整路径--从http开始到问号结束
        System.out.println(req.getRequestURL());

        //2.获取请求的部分路径--从站点名/项目对外路径开始到问号前面结束
        System.out.println(req.getRequestURI());

        //3.获取请求参数的字符串
        System.out.println(req.getQueryString());

        //4.获取请求方法
        System.out.println(req.getMethod());

        //5.获取请求的协议版本
        System.out.println(req.getProtocol());

        //6.获取站点名
        System.out.println(req.getContextPath());
    }
}
